package com.xsmart.oa.services;

import com.baomidou.mybatisplus.plugins.Page;
import com.xsmart.common.constant.ResultConstant;
import com.xsmart.common.entity.RequestBean;
import com.xsmart.common.entity.ResponseBean;
import com.xsmart.oa.dao.DistributeOrderExcelDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author pansheng
 */
@Service
public class DistributeOrderExcelService {

    @Autowired
    DistributeOrderExcelDao distributeOrderExcelDao;

    public ResponseBean queryOrderExcel(RequestBean requestBean){
        String nickName = requestBean.getRequestParamString("nick_name");
        String orderSn = requestBean.getRequestParamString("order_sn");
        String orderStatus = requestBean.getRequestParamString("order_status");
        String shippingStatus = requestBean.getRequestParamString("shipping_status");
        String payStatus = requestBean.getRequestParamString("pay_status");
        List addTime = (List) requestBean.getRequestParam("add_time");
        String timeType = requestBean.getRequestParamString("timeType");
        Map paramMap = new HashMap<>();
        if (addTime != null && addTime.size() > 0){
            paramMap.put("addStartTime",addTime.get(0));
            paramMap.put("addEndTime",addTime.get(1));
        }
        paramMap.put("nickName",nickName);
        paramMap.put("orderSn",orderSn);
        paramMap.put("orderStatus",orderStatus);
        paramMap.put("shippingStatus",shippingStatus);
        paramMap.put("payStatus",payStatus);
        paramMap.put("timeType",timeType);

        ResponseBean responseBean =requestBean.getResponseBean();
        int currentPage=requestBean.getRequestParamInteger("currentPage",1);
        int pageSize=requestBean.getRequestParamInteger("pageSize",10);
        Page<Map<String,Object>> page=new Page<>(currentPage,pageSize);
        page.setRecords(distributeOrderExcelDao.queryOrderExcel(page,paramMap));
        responseBean.addResultPageItem("distributeOrderExcel",page);
        responseBean.setResult(ResultConstant.SUCCESS);
        return responseBean;
    }

}
